package com.jack.leetcode.每日一题;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/***
 * 决策树
 * @author zhangjie
 * @date 2020/4/25 14:40
 */
public class 全排列 {

    public List<List<Integer>> permute(int[] nums) {
        LinkedList<Integer> track = new LinkedList<>();
        List<List<Integer>> result = new ArrayList<>();
        backTrace(nums,track,result);
        return result;
    }

    private void backTrace(int[] nums,LinkedList<Integer> track,List<List<Integer>> result){
        if(track.size() == nums.length){
            result.add(new ArrayList<>(track));
        }

        for(int i = 0;i<nums.length;i++){
            if(track.contains(nums[i])){
                continue;
            }
            track.add(nums[i]);
            backTrace(nums,track,result);
            track.removeLast();
        }
    }
}
